package com.eagle.functioninterface;

import org.junit.Test;

import java.math.BigDecimal;
import java.util.function.*;

/**
 * int double long 与 Function Predicate Supplier Consumer两两组合形成的函数式接口,
 * 其中int double long 都是作为入参
 * {@link java.util.function.IntFunction}
 * {@link java.util.function.IntPredicate}
 * {@link java.util.function.IntSupplier}
 * {@link java.util.function.IntConsumer}
 * {@link java.util.function.DoubleFunction}
 * {@link java.util.function.DoublePredicate}
 * {@link java.util.function.DoubleSupplier}
 * {@link java.util.function.DoubleSupplier}
 * {@link java.util.function.DoubleConsumer}
 * {@link java.util.function.LongFunction}
 * {@link java.util.function.LongPredicate}
 * {@link java.util.function.LongSupplier}
 * {@link java.util.function.LongConsumer}
 *
 * @author qinlinsen
 */
public class PrimaryTypeTest17 {
    @Test
    public void testIntFunction() {
        IntFunction<BigDecimal> f = x -> BigDecimal.valueOf(x);
        final BigDecimal result = f.apply(3);
        System.out.println("result=" + result);
    }

    @Test
    public void testIntPredicate() {
        IntPredicate f = x -> x > 5;
        final boolean result = f.test(5);
        System.out.println(result);
    }

    @Test
    public void testIntSupplier() {
        IntSupplier f = () -> 3;
        final int result = f.getAsInt();
        System.out.println(result);
    }

    @Test
    public void testIntConsumer() {
        IntConsumer f = x -> System.out.println(x);

        f.accept(3);
    }


    @Test
    public void testDoubleFunction() {
        DoubleFunction<BigDecimal> f = x -> BigDecimal.valueOf(x);
        final BigDecimal result = f.apply(3);
        System.out.println("result=" + result);
    }

    @Test
    public void testDoublePredicate() {
        DoublePredicate f = x -> x > 5;
        final boolean result = f.test(4.9);
        System.out.println(result);
    }

    @Test
    public void testDoubleSupplier() {
        DoubleSupplier f = () -> 3;
        final double result = f.getAsDouble();
        System.out.println(result);
    }

    @Test
    public void testDoubleConsumer() {
        DoubleConsumer f = x -> System.out.println(x);

        f.accept(3);
    }


    @Test
    public void testLongFunction() {
        LongFunction<BigDecimal> f = x -> BigDecimal.valueOf(x);
        final BigDecimal result = f.apply(3);
        System.out.println("result=" + result);
    }

    @Test
    public void testLongPredicate() {
        LongPredicate f = x -> x > 5;
        final boolean result = f.test(5);
        System.out.println(result);
    }

    @Test
    public void testLongSupplier() {
        LongSupplier f = () -> 3;
        final double result = f.getAsLong();
        System.out.println(result);
    }

    @Test
    public void testLongConsumer() {
        LongConsumer f = x -> System.out.println(x);

        f.accept(3);
    }
}
